package com.qk;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class RedisDemo {
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;
    @Test
    public void RedisString()
    {
      /*  redisTemplate.opsForValue().set("name", "tom");
        Object name = redisTemplate.opsForValue().get("name");
        System.out.println(name);*/
/*        redisTemplate.opsForValue().set("age", 18,10, TimeUnit.SECONDS);*/
        Object age = redisTemplate.opsForValue().get("age");
        System.out.println(age);
    }
    @Test
    public void Redislist()
    {
     redisTemplate.opsForHash().put("user", "name", "tom");
    redisTemplate.opsForHash().put("user", "age", 18);
        System.out.println(redisTemplate.opsForHash().values("user"));
        System.out.println(redisTemplate.opsForHash().keys("user"));
        List< Object>  fields=new ArrayList<>();
        fields.add("name");
        fields.add("age");
        System.out.println(redisTemplate.opsForHash().multiGet("user", fields));

    }
    @Test
    public void testZset()
    {
        redisTemplate.opsForZSet().add("zset", "tom", 10);
        redisTemplate.opsForZSet().add("zset", "jerry", 20);
        redisTemplate.opsForZSet().add("zset", "lucy", 30);
        System.out.println(redisTemplate.opsForZSet().range("zset", 0, -1));
        System.out.println(redisTemplate.opsForZSet().reverseRange("zset", 0, -1));
        System.out.println(redisTemplate.opsForZSet().rangeByScore("zset", 0, 100));
        System.out.println(redisTemplate.opsForZSet().reverseRangeByScore("zset", 0, 100));
        Long zset = redisTemplate.opsForZSet().zCard("zset");
        System.out.println(zset);
    }
}

